home *** CD-ROM | disk | FTP | other *** search
- <!--//--><![CDATA[//><!--
-
- /**
- * singleton pattern for low memory usage
- */
- function SiteMapDataLoader( fileName ) {
- var xmlDoc = null;
-
- /**
- * init method
- */
- this.init = function( fileName) {
-
- try {
- xmlDoc = loadXML( fileName );
- } catch (e) {
- throw e;
- }
- }
-
-
- /**
- * load data from xml file method
- */
- var loadXML = function( fileName )
- {
- xmlDoc = null;
-
- if (document.implementation && document.implementation.createDocument)
- {
- xmlDoc = document.implementation.createDocument("", "", null);
- }
- else if (window.ActiveXObject)
- {
- xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
- }
- else
- {
- alert('Your browser can\'t handle this script');
- }
-
-
- xmlDoc.async = false;
- xmlDoc.load( fileName );
-
- if( xmlDoc == null ) {
- throw "could not create xmlDoc object";
- }
-
- return xmlDoc;
- }
-
- /**
- *
- */
- this.getData = function() {
- return xmlDoc;
- }
-
- this.init( fileName );
-
- }
-
- SiteMapDataLoader.__instance__ = null;
-
- SiteMapDataLoader.getInstance = function( fileName ) {
- if( this.__instance__ == null ) {
- this.__instance__ = new SiteMapDataLoader( fileName );
- }
-
- return this.__instance__;
- }
-
- function SiteMap() {
-
- var xmlDoc = null;
-
- var containerId = "siteMap";
-
- var rootElementId = "siteMapContainer";
-
- var startVisible = true;
-
- var startClosed = false;
-
- var startSectionsClosed = false;
-
- var labelTitle = "SiteMap";
-
- var labelBySection = false;
-
- var cssClass = "siteMapContainer";
-
- /**
- * init method
- */
- this.init = function( title ) {
-
- try {
-
- if( title != null ) {
- labelTitle = title;
- }
-
- var loader = SiteMapDataLoader.getInstance( "sitemap.xml" );
-
- xmlDoc = loader.getData();
- } catch (e) {
- throw e;
- }
- }
-
- this.setCSS = function ( css ) {
- cssClass = css;
- }
-
- this.setLabelBySection = function ( bySection ) {
- labelBySection = bySection;
- }
-
- this.setTitle = function( title ) {
- labelTitle = title;
- }
-
- this.getTitle = function() {
- return labelTitle;
- }
-
- /**
- *
- */
- var setLabelBySection = function( section, element ) {
-
- if( element != null ) {
-
- if( section != null ) {
-
- var title = section.getAttribute("title");
-
- var textElement = document.createTextNode(title);
-
- element.replaceChild( textElement, element.firstChild );
- element.appendChild( textElement );
- }
- }
- }
-
- /**
- *
- */
- this.process = function( id, container ) {
-
- if( xmlDoc != null ) {
-
- var element = HTMLCreateRootElement( rootElementId );
-
- var labelElement = HTMLCreateLabelFragment( element );
-
- var containerElement = HTMLCreateContainerFragment( labelElement );
-
- element.appendChild( labelElement );
-
- element.appendChild( containerElement );
-
- var array = xmlDoc.getElementsByTagName( "smc" );
-
- var createLabel = true;
-
- if( array != null ) {
-
- for( var index=0 ; index < array.length ; index++ ) {
-
- if( id != null ) {
- if( array[index].getAttribute("id") == id ) {
-
- if( labelBySection ) {
- setLabelBySection( array[index], labelElement );
- createLabel = false;
- }
-
- processSection( array[index], null, containerElement, createLabel );
- }
- } else {
- processSection( array[index], null, containerElement, createLabel );
- }
- }
-
- if( container != null ) {
- containerId = container;
- }
-
- // append to Id
- var container = document.getElementById( containerId );
-
- if( container ) {
- container.appendChild( element );
- }
-
-
- } else {
- throw "SiteMap::process() -> no root sections found";
- }
-
-
- } else {
- throw "SiteMap::process() -> xmlDoc is null";
- }
- }
-
-
- var processSection = function( section, parentSection, container, createLabel ) {
-
- if( section != null ) {
-
- var sectionHTMLContainer = HTMLCreateSection( section, container, createLabel );
-
- // process titles
- var titles = section.getElementsByTagName( "st" );
- var arrayTitles = new Array();
-
- for( var index = 0 ; index < titles.length ; index++ ) {
-
- if( titles[index].parentNode == section ) {
- arrayTitles.push( titles[index] );
- }
- }
-
- if( arrayTitles.length > 0 ) {
- HTMLCreateTitles( arrayTitles, sectionHTMLContainer );
- }
-
- // process sub sections
-
- var sections = section.getElementsByTagName( "sms" );
-
- var title = section.getAttribute( "title" );
-
- if( sections != null ) {
-
- for( var index = 0; index < sections.length ; index ++ ) {
-
- // getElementsByTagName returns all elements at all depths below so bypass this
- // check if parent element is at same depth
- if( sections[index].parentNode == section ) {
- processSection( sections[index], section, sectionHTMLContainer, true );
- }
- }
-
- } else {
- // no sub sections in section
- }
- } else {
- throw "SiteMap::processSection() -> section parameter is null";
- }
-
- }
-
-
- /**
- *
- */
- var HTMLCreateRootElement = function( idPrefix ) {
-
- var element = document.createElement( "div" );
-
- if( element == null ) {
- throw "SiteMap::HTMLCreateRootElement() -> could not create root element";
- }
-
- // visibility
- if( startVisible == true ) {
- element.style.display = "block";
- } else {
- element.style.display = "none";
- }
-
- // id + unique random number
- var attribute = document.createAttribute( "id" );
-
- if( attribute != null ) {
- attribute.nodeValue = createUniqueRandomId( idPrefix );
-
- element.setAttributeNode( attribute );
- } else {
- throw "SiteMap::HTMLCreateRootElement() -> could not create id attribute for root element";
- }
-
- attribute = document.createAttribute( "class" );
-
- if( attribute != null ) {
-
- attribute.nodeValue = cssClass;
-
- element.setAttributeNode( attribute );
- } else {
- throw "SiteMap::HTMLCreateRootElement() -> could not create style attribute for root element";
- }
-
- return element;
- }
-
- /**
- *
- */
- var HTMLCreateLabelFragment = function( element ) {
-
- var container = document.createElement("div");
- var h1Element = document.createElement( "h1" );
- var textElement = null;;
-
- if( setLabelBySection == true ) {
- textElement = document.createTextNode( getTitleOfFirstSection() );
-
- } else {
- textElement = document.createTextNode( labelTitle );
- }
-
- var attribute = document.createAttribute( "id" );
-
- if( attribute != null ) {
-
- if( element != null ) {
- attribute.nodeValue = element.getAttribute("id") + "_label";
- } else {
- attribute.nodeValue = createUniqueRandomId( "randomId" );
- }
-
- h1Element.setAttributeNode( attribute );
-
- } else {
- throw "SiteMap::HTMLCreateLabelFragment() -> could not create id attribute for h1 element";
- }
-
- var attribute = document.createAttribute( "class" );
-
- if( attribute != null ) {
-
- attribute.nodeValue = "opened";
-
- h1Element.setAttributeNode( attribute );
-
- } else {
- throw "SiteMap::HTMLCreateLabelFragment() -> could not create class attribute for h1 element";
- }
-
- h1Element.appendChild( textElement );
-
- var closeElement = document.createElement( "a" );
- textElement = document.createTextNode( "X" );
- closeElement.appendChild( textElement );
- attribute = document.createAttribute( "id" );
-
- if( attribute != null ) {
-
- if( element != null ) {
- attribute.nodeValue = element.getAttribute("id") + "_label_close";
- } else {
- attribute.nodeValue = createUniqueRandomId( "randomId" );
- }
- } else {
- throw "SiteMap::HTMLCreateLabelFragment() -> could not create id attribute for close element";
- }
-
- attribute = document.createAttribute( "href" );
-
- if( attribute != null ) {
-
- attribute.nodeValue = createUniqueRandomId( "javascript:void(0);" );
- closeElement.setAttributeNode( attribute );
-
- } else {
- throw "SiteMap::HTMLCreateLabelFragment() -> could not create href attribute for close element";
- }
-
- closeElement.className = "close";
-
- closeElement.onclick = function( event ) {
-
- // do not propagate event
- if (!event) var event = window.event;
- event.cancelBubble = true;
- if (event.stopPropagation) event.stopPropagation();
-
- var element = this.parentNode.parentNode.parentNode.removeChild( this.parentNode.parentNode );
-
- element.style.display = "none";
- };
-
- // h1Element.appendChild( closeElement );
-
- return h1Element;
- }
-
- /**
- *
- */
- var HTMLCreateContainerFragment = function( element ) {
-
- if( element != null ) {
-
- var container = document.createElement( "div" );
-
- if( container == null ) {
- throw "could not create container element";
- }
-
- var attribute = document.createAttribute( "id" );
-
- if( attribute != null ) {
-
- attribute.nodeValue = element.getAttribute("id") + "_container";
-
- container.setAttributeNode( attribute );
- } else {
- throw "could not create id attribute for container element";
- }
-
- attribute = document.createAttribute( "class" );
-
- if( attribute != null ) {
- attribute.nodeValue = "siteMapContainer_container";
-
- container.setAttributeNode( attribute );
- } else {
- throw "could not create style attribute for root element";
- }
-
- if( startClosed == true ) {
- container.style.display = "none";
- element.className = "closed";
- } else {
- container.style.display = "block";
- element.className = "opened";
- }
-
- element.onclick = function() {
-
-
-
- };
-
- return container;
- } else {
- throw "either rootElement or xmlDoc is null maybe even both ;)";
- }
- }
-
-
-
- /**
- *
- */
- var HTMLCreateSection = function( section, parentContainer, createLabel ) {
-
- if( section != null ) {
-
- var labelType = "h2";
-
- if( parentContainer != null ) {
- labelType = "h3";
- }
-
- var container = document.createElement( "dl" );
- var containerElements = document.createElement( "dt" );
-
- if( createLabel ) {
- var title = section.getAttribute( "title" );
- var containerLabel = document.createElement( labelType );
-
- var indicatorLabel = document.createTextNode( "- " );
-
- var labelText = document.createTextNode( title );
-
- containerLabel.onclick = function( event ) {
-
- var container = this.parentNode.childNodes[1];
- var indicator = this.childNodes[0];
-
- if( container != null ) {
-
- if( container.style.display == "block" ) {
- container.style.display = "none";
- indicator.nodeValue = "+ ";
- } else {
- container.style.display = "block";
- indicator.nodeValue = "- ";
- }
-
- }
-
- };
-
- containerLabel.appendChild( indicatorLabel );
- containerLabel.appendChild( labelText );
- container.appendChild( containerLabel );
- }
-
- container.appendChild( containerElements );
-
- if( startSectionsClosed == true ) {
- containerElements.style.display = "none";
- } else {
- containerElements.style.display = "block";
- }
-
-
- if( parentContainer == null ) {
- if( containerElement != null ) {
-
- containerElement.appendChild( container );
-
- return containerElements;
-
- } else {
- throw "SiteMap::createHTMLSection() -> container element is null";
- }
- } else {
- parentContainer.appendChild( container );
-
- return containerElements;
- }
-
- } else {
- throw "SiteMap::createHTMLSection() -> section parameter is null";
- }
- }
-
-
- this.closeAll = function(elemId) {
- var element = document.getElementById(elemId);
- if (element != null) {
- var nodes = element.getElementsByTagName('h3');
- var node = null;
- for (var i=0; i<nodes.length; i++) {
-
- node = nodes[i];
- node.onclick();
- }
-
- var nodes = element.getElementsByTagName('h2');
- var node = null;
- for (var i=0; i<nodes.length; i++) {
- node = nodes[i];
- node.onclick();
- }
- }
- }
-
- /**
- *
- */
- var HTMLCreateTitles = function( titles, container ) {
-
- if( titles != null ) {
-
- if( titles.length > 0 ) {
-
- if( container != null ) {
-
- var title = null;
- var containerElement = null;
- var labelElement = null;
- var labelTextElement = null;
- var attribute = null;
- var st = null;
-
- for( var index = 0 ; index < titles.length ; index++ ) {
-
- title = titles[index].getElementsByTagName( "t" )[0].firstChild.data;
- st = titles[index];
-
- if( title != null ) {
-
- containerElement = document.createElement( "dt" );
- labelElement = document.createElement( "a" );
-
- /* 2022 2027 8226 */
- indicatorTextElement = document.createTextNode( "\u2022 " );
-
- labelTextElement = document.createTextNode( title );
-
- attribute = document.createAttribute("href");
- attribute.nodeValue = "javascript:void(0);";
-
- labelElement.setAttributeNode( attribute );
-
- attribute = document.createAttribute("name");
- attribute.nodeValue = st.getAttribute("href");
-
- labelElement.setAttributeNode( attribute );
-
- labelElement.appendChild( indicatorTextElement );
- labelElement.appendChild( labelTextElement );
-
- labelElement.onclick = function() {
- switch_iframe_and_close_sitemap( this.getAttribute("name") );
-
- }
- containerElement.appendChild( labelElement );
- container.appendChild( containerElement );
-
- }
-
- }
-
- }
-
- }
-
- } else {
-
- }
- }
-
- /**
- * create unique random id making sure it does not belong to an attachted dom element
- */
- var createUniqueRandomId = function( prefix ) {
- // avoid creating element with existing id
- var rand;
-
- var found = true;
- var foundElement = null;
- var tempId = prefix;
-
- while( found ) {
- rand = Math.round( 1000 * Math.random() );
-
- tempId = prefix + "_" + rand;
-
- foundElement = document.getElementById( tempId );
-
- if( foundElement != null ) {
- found = true;
- } else {
- found = false;
- }
- }
-
- return tempId;
- }
-
-
- }
-
- //--><!]]>
-